﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Services;

namespace ZHDJ.MobileInterface
{
    /// <summary>
    /// GovernmentServicesCloudSMSServiceClient 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class GovernmentServicesCloudSMSServiceClient : System.Web.Services.WebService
    {

        /// <summary>
        /// 政务云平台短信发送
        /// </summary>
        /// <param name="conten">短信内容，不能超过1000个字符</param>
        /// <param name="mobiles">手机号码，多个手机号码以小写逗号分隔</param>
        /// <param name="validate">验证码（由接口提供）</param>
        /// <returns></returns>
        [WebMethod(Description = "（客户端）调用党建调用政务云平台发送短信接口(中转地址)")]
        public string SMSSend(string conten, string mobiles, string validate)
        {
            var webProxyUrl = ConfigurationManager.AppSettings["GovernmentServicesCloudSms.WebProxyUrl"];
            var proxyUserName = ConfigurationManager.AppSettings["GovernmentServicesCloudSms.ProxyUserName"];
            var proxyPassword = ConfigurationManager.AppSettings["GovernmentServicesCloudSms.ProxyPassword"];
            SXT.Party.Utility.GovernmentServicesCloudSMSService service = new SXT.Party.Utility.GovernmentServicesCloudSMSService() { };
            if (!string.IsNullOrEmpty(webProxyUrl))
            {
                WebProxy proxy = new WebProxy();
                proxy.Address = new Uri(webProxyUrl);
                if (!string.IsNullOrEmpty(proxyUserName))
                {
                    proxy.Credentials = new NetworkCredential(proxyUserName, proxyPassword);
                    service.UseDefaultCredentials = true;
                }
                service.Proxy = proxy;
            }
            string Result = string.Empty;
            Result = service.SMSSend(conten, mobiles, validate);
            return Result;          
        }
    }
}
